//
//  LBChatMessageHistoryViewController.m
//  app
//
//  Created by 刘文扬 on 16/9/12.
//  Copyright © 2016年 广东联结电子商务有限公司. All rights reserved.
//

#import "LBChatMessageHistoryViewController.h"

@interface LBChatMessageHistoryViewController ()

@end

@implementation LBChatMessageHistoryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide) name:UIKeyboardDidHideNotification object:nil];
    
//    BACK(^(){
//        RCMessage *firstMessage = [self.conversationDataRepository lastObject];
//        
//        NSArray *messages = [[RCIMClient sharedRCIMClient] getHistoryMessages:ConversationType_GROUP targetId:self.targetId oldestMessageId:firstMessage.messageId count:19];
//        
//        NSMutableArray *mutableMessage = [[NSMutableArray alloc] init];
//        for (NSInteger i = 18; i >= 0; --i) {
//            RCMessage *message = messages[i];
//            RCMessageModel *model = [[RCMessageModel alloc] initWithMessage:message];
//            [mutableMessage addObject:model];
//        }
//        [mutableMessage addObject:firstMessage];
//        WS(weakSelf)
//        MAIN(^(){
//            weakSelf.conversationDataRepository = mutableMessage;
//            [weakSelf.conversationMessageCollectionView reloadData];
//            
//            [weakSelf scrollToBottomAnimated:NO];
//            [LBLoadingView dismiss];
//        });
//    });
    // Do any additional setup after loading the view.
}

//-(void)keyboardWillHide
//{
//    CGRect collectionRect = self.conversationMessageCollectionView.frame;
//    
//    NSLog(@"%@",NSStringFromCGRect(collectionRect));
//    
//    collectionRect.size.height = SCREEN_H - 40 - 40 - 64;
//    
//    collectionRect.origin.y = 0;
//    
//    self.conversationMessageCollectionView.frame = collectionRect;
//}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    [super scrollViewDidScroll:scrollView];
    CGRect collectionRect = self.conversationMessageCollectionView.frame;
    if (collectionRect.size.height != [UIScreen mainScreen].bounds.size.height - 40 - 40 - 64) {
        collectionRect.size.height = [UIScreen mainScreen].bounds.size.height - 40 - 40 - 64;
        
        collectionRect.origin.y = 0;
        
        self.conversationMessageCollectionView.frame = collectionRect;
    }
}

-(void)didLongTouchMessageCell:(RCMessageModel *)model inView:(UIView *)view
{
    [self becomeFirstResponder];
    [super didLongTouchMessageCell:model inView:view];
}


-(void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    self.chatSessionInputBarControl.hidden = YES;
    
    CGRect collectionRect = self.conversationMessageCollectionView.frame;
    
    NSLog(@"%@",NSStringFromCGRect(collectionRect));
    
    collectionRect.size.height = [UIScreen mainScreen].bounds.size.height - 40 - 40 - 64;
    
    collectionRect.origin.y = 0;
    
    self.conversationMessageCollectionView.frame = collectionRect;
    
    [self scrollToBottomAnimated:NO];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
